#include "CImgGraphics.h"

CImgGraphics::CImgGraphics()
{
	//Khoi tao canvas
	CImg<int> c(400, 300, 1, 255);
	canvas = c;
	canvas.fill(0);
}

void CImgGraphics::drawLine(int x1, int y1, int x2, int y2, string stroke, int strokeWidth)
{
	string _stroke = stroke;
	//Parse chuoi stroke de lay thong tin cho color
	int red = Parse(stroke);
	int green = Parse(stroke);
	int blue = Parse(stroke);
	const unsigned char color[] = {red, green, blue};

	//Ve duong thang
	canvas.draw_line(x1, y1, x2, y2, color);

	//Hien thi len man hinh
	CImgDisplay display(canvas, "CImg demo", 0);
	while(!display.is_closed()){
		display.wait();
	}

	//Luu line nay vao trong chuoi listObjects de co the Save tap tin
	stringstream list;
	list << "<line x1=" << "\"" << x1 << "\"" << " y1=" << "\"" << y1 << "\"";
	list << " x2=" << "\"" << x2 << "\"" << " y2=" << "\"" << y2 << "\"";
	list << " stroke=" << "\"" << _stroke << "\""; 
	list << " stroke-width=" << "\"" << strokeWidth << "\"" << "/>";
	getListObjects() += list.str();
}

void CImgGraphics::drawRectangle(int x, int y, int width, int height, string stroke, int strokeWidth, string fill)
{
	string _stroke = stroke;
	string _fill = fill;
	//Parse chuoi stroke de lay thong tin cho color
	int red = Parse(stroke);
	int green = Parse(stroke);
	int blue = Parse(stroke);
	const unsigned char color[] = {red, green, blue};

	//Ve hinh chu nhat
	canvas.draw_rectangle(x, y, x+width, y+height, color);

	//Hien thi len man hinh
	CImgDisplay display(canvas, "CImg demo 2", 0);
	while(!display.is_closed()){
		display.wait();
	}

	//Luu hinh chu nhat nay vao trong chuoi listObjects de co the Save tap tin
	stringstream list;
	list << "<rect x=" << "\"" << x << "\"" << " y=" << "\"" << y << "\"";
	list << " width=" << "\"" << width << "\"" << " height=" << "\"" << height << "\"";
	list << " stroke=" << "\"" << _stroke << "\""; 
	list << " stroke-width=" << "\"" << strokeWidth << "\"";
	list << " fill=" << "\"" << _fill << "\"" << "/>";
	getListObjects() += list.str();
}
void CImgGraphics::drawEllipse(int cx, int cy, int rx, int ry, string stroke, int strokeWidth, string fill)
{
	string _stroke = stroke;
	string _fill = fill;
	//Parse chuoi stroke de lay thong tin cho color
	int red = Parse(stroke);
	int green = Parse(stroke);
	int blue = Parse(stroke);

	//Ve hinh ellipse
	const unsigned char color[] = {red, green, blue};
	canvas.draw_ellipse(cx, cy, rx, ry, 1, color);
	
	//Hien thi len man hinh
	CImgDisplay display(canvas, "CImg demo", 0);
	while(!display.is_closed()){
		display.wait();
	}

	//Luu vao chuoi listObjects de co the Save tap tin
	stringstream list;
	list << "<ellipse cx=" << "\"" << cx << "\"" << " cy=" << "\"" << cy << "\"";
	list << " rx=" << "\"" << rx << "\"" << " ry=" << "\"" << ry << "\"";
	list << " stroke=" << "\"" << _stroke << "\""; 
	list << " stroke-width=" << "\"" << strokeWidth << "\"";
	list << " fill=" << "\"" << _fill << "\"" << "/>";
	getListObjects() += list.str();
}